import sphRequest from '@/utils/sphRequest'

// 商品详情数据类型
export interface skuAttrValueData {
  id: number
  attrId: number
  valueId: number
  skuId: number
}
export interface skuImageData {
  id: number
  skuId: number
  imgName: string
  imgUrl: string
  spuImgId: number
  isDefault: string
}
export interface skuInfo {
  id: number
  spuId: number
  price: number
  skuName: string
  skuDesc: string
  weight: string
  tmId: number
  category3Id: number
  skuDefaultImg: string
  isSale: number
  skuImageList: skuImageData[]
  skuAttrValueList: skuAttrValueData[]
  skuSaleAttrValueList: null
}
export interface spuSaleAttrValueData {
  id: number
  spuId: number
  baseSaleAttrId: number
  saleAttrValueName: string
  saleAttrName: string
  isChecked: string
}

export interface spuSaleAttrData {
  id: number
  spuId: number
  baseSaleAttrId: number
  saleAttrName: string
  spuSaleAttrValueList: spuSaleAttrValueData[]
}

interface categoryViewData {
  id: number
  category1Id: number
  category1Name: string
  category2Id: number
  category2Name: string
  category3Id: number
  category3Name: string
}
interface detailData {
  valuesSkuJson: string
  price: number
  categoryView: categoryViewData
  spuSaleAttrList: spuSaleAttrData[]
  skuInfo: skuInfo
}

interface reqData {
  data: detailData
}
export default {
  // 获取商品信息
  reqGoodInfo(skuId: number) {
    return sphRequest.get<any, reqData>(`/api/item/${skuId}`)
  },
  // 添加购物车
  reqAddGoods(skuId: string | number, skuNum: string | number) {
    return sphRequest.post<any, any>(`/api/cart/addToCart/${skuId}/${skuNum}`)
  }
}
